<?php
/**
 * Created by IntelliJ IDEA.
 * User: XD
 * Date: 2017/8/21
 * Time: 9:57
 */

namespace MyProject;

  function writeName()
  {
      echo "Kai Jim Refsnes";
  }

  echo "My name is ";
  writeName();


  // 添加参数
function writeName2($fname)
{
    echo $fname . " Refsnes.<br>";
}

echo "My name is ";
writeName2("Kai Jim");
echo "My sister's name is ";
writeName2("Hege");
echo "My brother's name is ";
writeName2("Stale");

// 多参数

function writeName3($fname,$punctuation)
{
    echo $fname . " Refsnes" . $punctuation . "<br>";
}

echo "My name is ";
writeName3("Kai Jim",".");
echo "My sister's name is ";
writeName3("Hege","!");
echo "My brother's name is ";
writeName3("Ståle","?");

//如需让函数返回一个值，请使用 return 语句。

function add($x,$y)
{
    $total = $x+$y;
    return $total;

}

echo "1 + 16 = " . add(1,16);


//魔术变量

echo '这是第 “ '  . __LINE__ . ' ” 行';  //显示行

echo '该文件位于 “ '  . __DIR__ . ' ” ';  //该文件位于 “ E:\wamp\www\test ”

function test() {
    echo  '函数名为：' . __FUNCTION__ ;  //函数名为：test
}
test();

class test {
    function _print() {
        echo '类名为：'  . __CLASS__ . "<br>";
        echo  '函数名为：' . __FUNCTION__ ;
    }
}
$t = new test();
$t->_print();

//类名为：test
//函数名为：_print

class Base {
    public function sayHello() {
        echo 'Hello ';
    }
}

trait SayWorld {
    public function sayHello() {
        parent::sayHello();
        echo 'World!';
    }
}

class MyHelloWorld extends Base {
    use SayWorld;
}

$o = new MyHelloWorld();
$o->sayHello();

function test1() {
    echo  '函数名为：' . __METHOD__ ;
}
test1();  //test



echo '命名空间为："', __NAMESPACE__, '"'; // 输出 "MyProject"
?>